<?php
namespace Admin\Model;
use Think\Model;

class NodeModel extends Model{

	protected $_validate = array(
		array('pid','number','父节点不能为空！',1),
		array('title','require','描述不能为空！'),
		array('name','checkNode','名称已经存在',0,'callback'),
		array('level',array(1,2,3),'节点类型非法！',1,'in'), 
		//array('display',array(0,1,2),'显示类型非法！',1,'in'),
	 );

    public function checkNode() {
        $map['name']	 =	 $_POST['name'];
        $map['pid']	=	isset($_POST['pid'])?$_POST['pid']:0;
        $map['status'] = 1;
        if(!empty($_POST['id'])) {
            $map['id']	=	array('neq',$_POST['id']);
        }
        $result	=	$this->where($map)->field('id')->find();
        if($result) {
            return false;
        }else{
            return true;
        }
    }    

}